﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IM.Interfaces.GUI;
using IM.Interfaces.Protocols;
using IM.Interfaces;
using IM.DataTypes;


namespace IM.GUI.ContactList
{
    public partial class ContactListWindow : UserControl, IContactList
    {
        public event ObjectHandler OnLoad;
        public event ObjectHandler OnQuit;

        internal static ControlEventHandler OnControlCreated;

        public ContactListWindow()
        {
            InitializeComponent();

            this.HandleDestroyed += new EventHandler(ContactListWindow_FormClosing);
            this.contactList1.ShowOnlyOnlineContacts = this.chckShowOnline.Checked;

            if (OnControlCreated != null)
                OnControlCreated(this, new ControlEventArgs(this));
        }
        
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            this.contactList1.Invalidate();
        }

        void ContactListWindow_FormClosing(object sender, EventArgs e)
        {
            if (this.OnQuit != null)
                this.OnQuit(sender);
        }


        public void UpdateContactList(User[] users)
        {
            this.contactList1.UpdateContacts(users);
        }

        private void chckShowOnline_CheckedChanged(object sender, EventArgs e)
        {
            this.contactList1.ShowOnlyOnlineContacts = this.chckShowOnline.Checked;
        }
    }
}
